<template>
  <div>
    <el-dialog
      title="新增区域"
      width="60%"
      :visible.sync="visible"
    >
      <el-form ref="form" label-width="80px" :model="form" :rules="rules">
        <el-form-item label="点位名称" prop="name">
          <el-input
            v-model="form.name"
            type="text"
            placeholder="请输入内容"
            maxlength="10"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="所在区域" label-width="80px" prop="region">
          <el-select v-model="form.region" placeholder="请选择">
            <el-option v-for="item in arr1" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="所属商圈" prop="businessType">
          <el-select v-model="form.businessType" placeholder="请选择">
            <el-option v-for="item in arr" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="合作商" prop="ownerName">
          <el-select v-model="form.ownerName" placeholder="请选择">
            <el-option v-for="item in arr2" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item ref="addrone" label="详细地址" prop="addr">
          <el-cascader
            v-for="item in date2"
            :key="item.id"
            v-model="form.addr"
            @change="handleChange"
          />
        </el-form-item>
        <el-form-item label="详细地址">
          <el-input
            v-for="item in date2"
            :key="item.id"
            v-model="form.addr"
            type="textarea"
            placeholder="请输入内容"
            maxlength="60"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible=false">取 消</el-button>
        <el-button type="primary" @click="surePoin">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { addNodelist, addBusinessType, addSearch, addPartner } from '@/api/point'
export default {
  name: 'DikedeAdd',

  data() {
    return {
      visible: false,
      arr: [],
      arr1: [],
      arr2: [],
      form: {},
      data2: {
        addr: 'sdfsasf',
        areaCode: '110100',
        businessId: 1,
        createUserId: 1,
        name: this.form.name,
        ownerId: 2,
        ownerName: this.form.ownerName,
        regionId: '1305439798119075841'
      },
      rules: {
        name: [{ required: true, message: '必填', trigger: 'blur' }],
        region: [{ required: true, message: '必填', trigger: 'blur' }],
        businessType: [{ required: true, message: '必填', trigger: 'blur' }],
        ownerName: [{ required: true, message: '必填', trigger: 'blur' }]
      },
      params: {
        pageIndex: 1,
        pageSize: 1000
      }
    }
  },

  mounted() {
    this.addBusinessType()
    this.addSearch()
    this.addPartner()
  },

  methods: {
    handleChange(value) {
      console.log(value)
    },
    // 商圈列表
    async addBusinessType() {
      const res = await addBusinessType()
      // console.log(res)
      this.arr = res
    // console.log(this.arr)
    },
    // 所在区域
    async addSearch() {
      const res = await addSearch()
      // console.log(res)
      this.arr1 = res.currentPageRecords
    // console.log(res.currentPageRecords)
    // console.log(this.arr1)
    },
    // 合作商列表
    async addPartner() {
      const res = await addPartner(this.params)
      this.arr2 = res.currentPageRecords
    // console.log(this.arr2)
    },
    async surePoin() {
      try {
      // await this.$refs.form.validate()
        const res = await addNodelist(this.data2)
        console.log(res)
      } catch (e) {
        console.log(e)
      }
    }
  }
}

</script>

<style lang="scss" scoped>

</style>
